import matplotlib
matplotlib.use('TkAgg')
import  matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
sns.set_style('darkgrid')

# 中文乱码
# plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['font.sans-serif'] = ['Heiti TC']
df = pd.read_excel('./data/mrbook.xlsx')
x = [1,2,3,4,5,6]
y1 = df['销量']
y2 = df['rate']
fig = plt.figure()
ax1 = fig.add_subplot(111)
plt.title('销量情况对比')
#图表x轴
plt.xticks(x,['1月','2月','3月','4月','5月','6月'])
ax1.bar(x,y1,label='left')
# y轴标签
ax1.set_ylabel('销量（册）')
# 共享x轴，添加另一条y轴
ax2 = ax1.twinx()
ax2.plot(x,y2,color='black',linestyle='--',marker='o',linewidth=2,label=u'增长率')
ax2.set_ylabel(u'增长率')

for a,b in zip(x,y2):
    plt.text(a,b+0.02,'%.2f' % b, ha='center',va='bottom',fontsize=10,color='red')

plt.show()











